﻿using System;
using System.Collections.Generic;

using MSAcademic.v2.Infrastructure.AccessRights;
using MSAcademic.v2.Infrastructure.Gallery;
using MSAcademic.v2.Infrastructure.Login;
using MSAcademic.v2.Infrastructure.Picture;
using MSAcademic.v2.Infrastructure.User;

namespace MSAcademic.v2.Web.Areas.Admin.Models.Gallery
{
    public partial class GalleryViewModel
    {
        public int GalleryId { get; set; }

    }

    public partial class GalleryViewModel
    {
        public IGallery Gallery
        {
            get
            {
                if (_gallery == null)
                {
                    _gallery = new Lazy<IGallery>(() => _galleryQueries.GetGallery(this.GalleryId));
                }
                return _gallery.Value;
            }
        }
        private Lazy<IGallery> _gallery;
        public List<IPicture> Pictures
        {
            get
            {
                if (_pictures == null)
                {
                    _pictures = new Lazy<List<IPicture>>(() => _pictureQueries.GetPictures(this.GalleryId));
                }
                return _pictures.Value;
            }
        }
        private Lazy<List<IPicture>> _pictures;
    }

    public partial class GalleryViewModel
    {
        public IUser SignedInUser
        {
            get
            {
                if (_signedInUser == null)
                {
                    _signedInUser = new Lazy<IUser>(() => _loginService.TryGetSignedInUser());
                }
                return _signedInUser.Value;
            }
        }
        private Lazy<IUser> _signedInUser;

        public bool CanView
        {
            get
            {
                if (_canView == null)
                {
                    _canView = new Lazy<bool>(() => this.SignedInUser != null);
                }
                return _canView.Value;
            }
        }
        private Lazy<bool> _canView;
    }

    public partial class GalleryViewModel
    {
        private readonly IGalleryQueries _galleryQueries;
        private readonly IPictureQueries _pictureQueries;
        private readonly ILoginService _loginService;
        private readonly IAccessRightsService _accessRightsService;

        public GalleryViewModel(IGalleryQueries galleryQueries,
                                IPictureQueries pictureQueries,
            ILoginService loginService,
            IAccessRightsService accessRightsService)
        {
            _galleryQueries = galleryQueries;
            _pictureQueries = pictureQueries;
            _loginService = loginService;
            _accessRightsService = accessRightsService;
        }
    }

}